package leedcode_path.shuzhu;

public class 有序数组的平方 {
    public int[] sortedSquares(int[] nums) {
        int left=0;
        int right=nums.length-1;
        int[] res=new int[nums.length];
        for (int i = nums.length-1; i >= 0; i--) {
            if (nums[left]*nums[left]>nums[right]*nums[right]){
                res[i]=nums[left]*nums[left];
                left++;
            }else{
                res[i]=nums[right]*nums[right];
                right--;
            }
        }
        return res;

    }
}
